package com.hanyxx.thread;
/**
 * 测试volatile关键字
 * @author layman
 * @date 2021/2/6
 */
public class Demo09 {
    public static void main(String[] args) throws InterruptedException {
        Demo09Service service = new Demo09Service();
        service.start();
        Thread.sleep(100);
        System.out.println(Thread.currentThread().getName()+" 线程准备停止doSomething方法");
        service.isContinue = false;
    }
}
class Demo09Service extends  Thread{
    public volatile boolean isContinue = true;

    @Override
    public void run() {
        doSomething();
    }
    public void doSomething(){
        System.out.println("doSomething方法执行开始----");
        while(isContinue){
        }
        System.out.println("doSomething方法执行结束----");
    }
}
